<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link href="../css/element.css" rel="stylesheet"/>
    <link href="../css/styleindex.css" rel="stylesheet"/>
    <style>
    .el-input__inner{
      border: 0;
      font-size: 1rem;
      text-align: center;
    }.el-input__prefix{
      display: none;
    }
    </style>
</head>
<body style="background:#EFF0F4;">

  <div class="mui-content">
    <div id="vm" class="x-examok" v-cloak>
      <div class="x-header-g" id="header">
        <a class="x-header-arrow" @click="api.closeWin()"></a>
        <div class="x-header-t">{{headtitle}}档案</div>
      </div>
      <!--  -->
      <div class="x-ico-month">
        <el-date-picker v-model="cardsmonth" type="month" placeholder="选择月" @change="getmonth" format="yyyy 年 MM 月" value-format="yyyyMM" :editable="notkey"></el-date-picker>
      </div>
      <!--  -->
      <div class="x-ut-box">
        <div class="x-ut-top">
          <div class="x-inc-num">系统参与门店：<span class="x-inc-g">{{personnum}}个</span></div>
          <div class="x-inc-num">本组参与店面：<span class="x-inc-g">{{personnum2}}个</span></div>
        </div>
        <div class="x-ut-bot">
          <template>
            <el-tabs v-model="activeName" @tab-click="handleClick" stretch="true">
              <el-tab-pane :label="'系统'+headtitle+'信息'" name="first">
                <div class="x-inc-num">系统当月{{headtitle}}：{{monthnum}}人</div>
                <template>
                  <el-table :data="tableData">
                    <el-table-column label="序号" width="50" type="index"></el-table-column>
                    <el-table-column label="组别" width="">
                      <template slot-scope="scope">
                        {{scope.row.dept_title}}
                      </template>
                    </el-table-column>
                    <el-table-column :label="headtitlenum" width="">
                      <template slot-scope="scope">
                        {{scope.row.n}}
                      </template>
                    </el-table-column>
                    <el-table-column label="占比" width="">
                      <template slot-scope="scope">
                        {{scope.row.rate}}%
                      </template>
                    </el-table-column>
                  </el-table>
                </template>
              </el-tab-pane>
              <el-tab-pane :label="'本组'+headtitle+'信息'" name="second">
                <div class="x-inc-num">本组当月{{headtitle}}：{{monthnum}}人</div>
                <template>
                  <el-table :data="tableDatatwo" @cell-click='goincardlist'>
                    <el-table-column label="序号" width="50" type="index"></el-table-column>
                    <el-table-column label="组别" width="">
                      <template slot-scope="scope">
                        {{scope.row.dept_title}}
                      </template>
                    </el-table-column>
                    <el-table-column :label="headtitlenum" width="">
                      <template slot-scope="scope">
                        {{scope.row.n}}
                      </template>
                    </el-table-column>
                    <el-table-column label="占比" width="">
                      <template slot-scope="scope">
                        {{scope.row.rate}}%
                      </template>
                    </el-table-column>
                    <el-table-column label="详细信息" width="">
                      <el-button type="text">查看</el-button>
                    </el-table-column>
                  </el-table>
                </template>
              </el-tab-pane>
            </el-tabs>
          </template>
        </div>
      </div>
    </div>
  </div>

  <script type="text/javascript" src="../script/vue.js"></script>
  <script type="text/javascript" src="../script/element.js"></script>
  <script type="text/javascript" src="../script/api.js"></script>
  <script type="text/javascript" src="../script/base.js"></script>
	<script>
apiready = function () {
    var ttype = api.pageParam.type;
    console.log(ttype);
    $api.fixStatusBar($api.byId('header'));

    //
    var vm = new Vue({
      el:'#vm',
      data(){
        return{
          istype:'',//标记在职 离职
          headtitle:'',
          headtitlenum:'',
          cardsmonth:'',
          tableData:[],
          tableDatatwo:[],
          chancedata:'',
          personnum:'',
          personnum2:'',
          notkey:false,
          activeName: 'first',
          ishandletype:'0',//标记选项卡
          monthnum:'',//系统当月在职人数 本组当月在职人数

        }
      },
      created:function() {
        var that=this;


      },
      mounted:function(){
        var that=this;
        that.istype = ttype;
        if(that.istype=='1'){
          that.headtitle = '在职';
          that.headtitlenum = '在职人数';
          that.getdata('1')
        }if(that.istype=='2'){
          that.headtitle = '离职';
          that.headtitlenum = '离职人数';
          that.getdatatwo('1')
        }
        //当前月份
        var date = new Date();
        var year = date.getFullYear();
        var month = date.getMonth()+1;
        if(month<10){
          month = '' + 0 + month;
        }
        var toMonth = '' + year + month ;
        this.cardsmonth = toMonth;

      },
      methods: {
        //选项卡
        handleClick:function(tab, event){
          let id = event.target.getAttribute('id').split('-');
          let whitetab = id.join('').substring(3,9);
          let that = this;
          if(that.istype=='1'){
            if(whitetab=='first'){//
              that.ishandletype = '0';
              that.getdata('1')//系统
            }else if(whitetab=='second'){//
              that.ishandletype = '1';
              that.getdata('2')//本组
            }
          }else if(that.istype=='2'){
            if(whitetab=='first'){//
              that.ishandletype = '0';
              that.getdatatwo('1')//系统
            }else if(whitetab=='second'){//
              that.ishandletype = '1';
              that.getdatatwo('2')//本组
            }
          }

        },
        //离职
        getdatatwo:function(type){
          let that=this;
          api.ajax({
            url:baseurl+'api/person/comLeaveList',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                date:that.cardsmonth,
                 _gid:$api.getStorage('groupid'),
                 type:type
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                that.personnum = ret.data.sysCount;
                that.personnum2 = ret.data.groupCount;
                that.monthnum = ret.data.count;
                if(that.ishandletype=='0'){
                  that.tableData = ret.data.list;
                }else{
                  that.tableDatatwo = ret.data.list;
                }

              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
        //在职
        getdata:function(type){
          let that=this;
          api.ajax({
            url:baseurl+'api/person/comInworkList',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                date:that.cardsmonth,
                 _gid:$api.getStorage('groupid'),
                 type:type
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                that.personnum = ret.data.sysCount;
                that.personnum2 = ret.data.groupCount;
                that.monthnum = ret.data.count;
                if(that.ishandletype=='0'){
                  that.tableData = ret.data.list;
                }else{
                  that.tableDatatwo = ret.data.list;
                }

              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
        //
        getmonth:function(val){
          var that = this;
          console.log(val);
          // console.log(val.getMonth()+1);
          // var tmon = val.getMonth()+1
          // if(tmon<10){
          //   tmon=''+0+tmon
          // }
          // console.log(''+val.getFullYear() + tmon);
          that.chancedata = val;
          if(that.istype=='1'){//在职
            if(that.ishandletype=='0'){
              that.getdata('1')
            }else{
              that.getdata('2')
            }

          }else if(that.istype=='2'){
            if(that.ishandletype=='0'){
              that.getdatatwo('1')
            }else{
              that.getdatatwo('2')
            }
          }

        },
        //查看
        goincardlist:function(val){
          var that=this;
          console.log(JSON.stringify(val));
          api.openWin({
              name: 'incardlist',
              url: './incardlist.html',
              pageParam: {
                  ison:that.istype,//1在职 2离职
                  id:val.deptid,
                  datemonth:val.in_date,//日期
                  groupname:val.dept_title,//组
                  shopid:val.shopid,
              }
          });
        },
      }
    })
	}


	</script>
</body>
</html>
